/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package modules

import geb.module.Select
import geb.test.GebSpecWithCallbackServer

class SelectSnippetSpec extends GebSpecWithCallbackServer {

    def "using select module"() {
        given:
        html """
            // tag::html[]
            <html>
                <body>
                    <select name="artist">
                        <option value="1">Ima Robot</option>
                        <option value="2">Edward Sharpe and the Magnetic Zeros</option>
                        <option value="3">Alexander</option>
                    </select>
                </body>
            </html>
            // end::html[]
        """

        when:
        // tag::example[]
        def select = $(name: "artist").module(Select)
        select.selected = "2"

        // end::example[]
        then:
        // tag::example[]
        assert select.selected == "2"
        assert select.selectedText == "Edward Sharpe and the Magnetic Zeros"

        // end::example[]
        when:
        // tag::example[]
        select.selected = "Alexander"

        // end::example[]
        then:
        // tag::example[]
        assert select.selected == "3"
        assert select.selectedText == "Alexander"
        // end::example[]
    }
}
